<?php
/**
 * @version		0.2.0 joomla zmluvy $
 * @package		com_zjmluvy
 * @copyright	Copyright © 2011 - All rights reserved.
 * @license		GNU/GPL
 * @author    AdrianKo		
 * @website   http://code.google.com/p/joomla-zmluvy
 *
 *
 *1.3.2012
 */

// no direct access
defined('_JEXEC') or die('Restricted access');

jimport( 'joomla.application.component.view' );
jimport( 'joomla.html.parameter' );

class jzmluvyViewUpravaFaktury extends Jview
{
	
  function display($tpl = null){
		global $mainframe, $option;
		
		$db 		=& JFactory::getDBO();
		$params	= &JComponentHelper::getParams('com_jzmluvy');
    $nastavenie = & jzmluvyHelper::nastavenie();
    		
		//get data from model
		$model		= & $this->getModel();
		$item     	= & $this->get( 'Data');
		
		//*** zoznam dodavatelov casto pouzivanych
		$dod = array();   //*** TYP urcuje ze su vybrani len partneri 
    $query = 'SELECT *'
			. ' FROM #__jzmluvy_partner'
			. ' WHERE published = 1' // len povoleny zobrazit
      . ' AND typ = 1' // len dodavatelia
      . ' ORDER BY reserverd DESC, title ASC' // triedenie podla favorita, mena
		;
		$db->setQuery( $query );
		
    $dod[] = JHTML::_('select.option',  0 , ' - '.JText::_( 'fa_EDIT_PARTNER_VYBER' ).' - ');
		foreach( $db->loadObjectList() as $obj )
		{
			$ident 	= $obj->reserverd ? ' *' : ''; // identifikacia favorita
			$dod[] = JHTML::_('select.option',  $obj->id, $obj->title.$ident);
		}
		$lists['dod'] 	= JHTML::_('select.genericlist',   $dod, 'dodavatel', 'class="inputbox" size="1"', 'value', 'text', $item->dodavatel );
    
    // typ faktury ... prijata; odoslan
    $typ_faktury[] = JHTML::_('select.option',  0, JText::_( 'fa_EDIT_FAK_PRIJATA' ));
    $typ_faktury[] = JHTML::_('select.option',  1, JText::_( 'fa_EDIT_FAK_ODOSLANA' ));
    $lists['typ_faktury'] 	= JHTML::_('select.genericlist', $typ_faktury, 'typ', 'class="inputbox" size="1"', 'value', 'text', $item->typ );

    // sposob uhrady ... prijata; odoslan
    $uhrada[] = JHTML::_('select.option',  1, JText::_( 'fa_EDIT_SPOSOB_UHRAD_BEZHOTOVOSTNE' ));
    $uhrada[] = JHTML::_('select.option',  2, JText::_( 'fa_EDIT_SPOSOB_UHRAD_VHOTOVOSTI' ));
    $lists['uhrada'] 	= JHTML::_('select.genericlist', $uhrada, 'sposob_uhrady', 'class="inputbox" size="1"', 'value', 'text', $item->sposob_uhrady );

    //kontakty
		$kontakty = array();
    $query = 'SELECT *'
			. ' FROM #__contact_details'
			. ' WHERE published = 1'
			. ' ORDER BY name'
		;
		$db->setQuery( $query );
		
    //*** zoznam kontaktov ... zodpovednych
		$kontakty[] = JHTML::_('select.option',  0 , ' - '.JText::_( 'fa_EDIT_ZODPOVEDNA_OSOBA_VYBER' ).' - ');
		foreach( $db->loadObjectList() as $obj )
		{
			$kontakty[] = JHTML::_('select.option',  $obj->id, $obj->name);
		}
		$lists['kontakty'] 	= JHTML::_('select.genericlist', $kontakty, 'created_by_alias', 'class="inputbox" size="1"', 'value', 'text', $item->created_by_alias );  

    //*** zoznam zmluv
		$dodatok = array();  
    $query = 'SELECT *'
			. ' FROM #__jzmluvy'
			. ' WHERE catid = 2'
      . ' AND typ = 0'
      . ' ORDER BY faktura'
		;
		$db->setQuery( $query );
		
		$zmluva[] = JHTML::_('select.option',  0 , ' - Vyberte zmluvu -------- ');
		foreach( $db->loadObjectList() as $obj )
		{
     // cislo zmluvy aj predmet .. skrateny na 30 naskov
     $vyb = $obj->faktura." - ".trim(mb_substr($obj->fulltext, 0, 30, 'UTF-8')).'...';
     $zmluva[] = JHTML::_('select.option',  $obj->id, $vyb);
		}
		$lists['zmluva'] 	= JHTML::_('select.genericlist',   $zmluva, 'typ', 'class="inputbox" size="1"', 'value', 'text', $item->typ );
    
   //*** zoznam objednavok
		$dodatok = array();  
    $query = 'SELECT *'
			. ' FROM #__jzmluvy'
			. ' WHERE catid = 3'
      // . ' AND typ = 0'
      . ' ORDER BY faktura'
		;
		$db->setQuery( $query );
		
		$objednavka[] = JHTML::_('select.option',  0 , ' - Vyberte objednávku - ');
		foreach( $db->loadObjectList() as $obj )
    {
     // cislo objednavky aj predmet .. skrateny na 30 naskov
     $vyb = $obj->faktura." - ".trim(mb_substr($obj->title, 0, 30, 'UTF-8')).'...';    
     $objednavka[] = JHTML::_('select.option',  $obj->id, $vyb);
		}
		$lists['objednavka'] 	= JHTML::_('select.genericlist',   $objednavka, 'sposob', 'class="inputbox" size="1"', 'value', 'text', $item->sposob );    
   
   		
    $this->assignRef('item', $item);
    $this->assignRef('params', $params);
    $this->assignRef('lists', $lists);
    $this->assignRef( 'nastavenie', $nastavenie );
    
		parent::display($tpl);
	}



}
?>